# 此程序为QQ空间自动点赞程序
from selenium import webdriver
import time
from selenium.webdriver.chrome.options import Options

def prase(user_id, password):
    Url = "https://qzone.qq.com/"
    #user_id = "3056009414"
    #password = "82324598232929ac"
    #driver = webdriver.PhantomJS("/home/mark/phantomjs-2.1.1-linux-x86_64/bin/phantomjs")

    options = Options()
    options.add_argument("--headless")
    options.add_argument("--disable-gpu")
    options.add_argument("--no-sandbox")
    driver = webdriver.Chrome(chrome_options=options)

    driver.get(Url)
    # 登录表单在页面的框架中，所以要切换到该框架
    driver.switch_to_frame("login_frame")
    # 通过使用选择器选择到表单元素进行模拟输入和点击按钮提交
    driver.find_element_by_id("switcher_plogin").click()
    driver.find_element_by_id("u").clear()
    driver.find_element_by_id("u").send_keys(user_id)
    driver.find_element_by_id("p").clear()
    driver.find_element_by_id("p").send_keys(password)
    # 点击过快会弹出安全验证页面(滑块)
    time.sleep(3)
    driver.find_element_by_id("login_button").click()
    #driver.switch_to.default_content()
    #print(driver.page_source)
    time.sleep(5)

    # 点赞模块
    InfoUrl = "https://user.qzone.qq.com/{}".format(user_id)
    driver.get(InfoUrl)
    btns = driver.find_elements_by_css_selector("i.fui-icon.icon-op-praise") # 此处是CSS选择器
    for btn in btns:
        btn.click()
        time.sleep(2)
    driver.quit()